#include "FPCH.h"

#include "FTextInstructions.h"

namespace Font
{

	TextInstructions::TextInstructions(Library* a_Library)
	{
		m_Library = a_Library;

		Clear();
	}
	
	TextInstructions::~TextInstructions()
	{
		
	}

	void TextInstructions::Clear()
	{
		SetCommand(Instruction::eEndOfData);

		m_TextLength = 0;
		m_CodePointCount = 0;
		m_InstructionCount = 0;
	}

	void TextInstructions::SetCommand(Instruction::List a_Type, unsigned int a_Data /*= 0*/)
	{
		m_CommandCurrent.type = a_Type;
		m_CommandCurrent.data = a_Data;

		m_InstructionCount++;
		if (a_Type == Instruction::eCodePoint)
		{
			m_CodePointCount++;
		}
	}

	unsigned int TextInstructions::GetCodePointCount()
	{
		return m_CodePointCount;
	}

	unsigned int TextInstructions::GetInstructionCount()
	{
		return m_InstructionCount;
	}

	const TextCommand& TextInstructions::GetCommand()
	{
		return m_CommandCurrent;
	}

	unsigned int TextInstructions::GetTextLength()
	{
		return m_TextLength;
	}


	InterfaceInstructions::InterfaceInstructions()
	{

	}

	InterfaceInstructions::~InterfaceInstructions()
	{

	}


	InstructionsUtf16::InstructionsUtf16(Library* a_Library)
	{
		m_Library = a_Library;
	}

	InstructionsUtf16::~InstructionsUtf16()
	{

	}

	void InstructionsUtf16::Clear()
	{

	}

	bool InstructionsUtf16::SetText(const unsigned char* a_String)
	{
		m_Text = (const wchar_t*)a_String;
		m_TextCursor = m_Text;
		m_TextLength = wcslen(m_Text);

		return true;
	}

	unsigned int InstructionsUtf16::GetTextLength()
	{
		return m_TextLength;
	}

	void InstructionsUtf16::SetCommand(Instruction::List a_Type, unsigned int a_Data /*= 0*/)
	{
		m_CommandCurrent.type = a_Type;
		m_CommandCurrent.data = a_Data;

		/*m_InstructionCount++;
		if (a_Type == Instruction::eCodePoint)
		{
			m_CodePointCount++;
		}*/
	}

	bool InstructionsUtf16::NextCommand()
	{
		wchar_t current = *m_TextCursor;

		bool result = true;

		switch (current)
		{

		case 0:
			{
				SetCommand(Instruction::eEndOfData);
				result = false;
				break;
			}

		case L'\r':
			{
				if (m_TextCursor[1] == '\n') { m_TextCursor++; }
				SetCommand(Instruction::eNewLine);
				break;
			}

		case L'\n':
			{
				SetCommand(Instruction::eNewLine);
				break;
			}

		case L'\t':
			{
				SetCommand(Instruction::eTab);
				break;
			}

		default:
			{
				SetCommand(Instruction::eCodePoint, (unsigned int)current);
				break;
			}

		}

		m_TextCursor++;

		return result;
	}

	const TextCommand& InstructionsUtf16::GetCommand()
	{
		return m_CommandCurrent;
	}

}; // namespace Font